#include <algorithm>
#include <cstdio>

#define lowbit(x) (x & (-x))

const int N = 100005;
int n, m, cnt, L, R, a[N], hash[N << 1], rt[N], lpos[N], rpos[N];

struct Query {
  int l, r, k, x, y;
  char opt;
} q[N];

struct Node {
  int ls, rs, val;
} tr[N << 7];

void modify(int &x, int l, int r, int pos, bool ad) {
  if (!x) x = ++cnt;
  ad ? tr[x].val++ : tr[x].val--;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    modify(tr[x].ls, l, mid, pos, ad);
  else
    modify(tr[x].rs, mid + 1, r, pos, ad);
}

int query(int l, int r, int k) {
  if (l == r) return l;
  int mid = (l + r) >> 1, sum = 0;
  for (int i = 1; i <= L; ++i) {
    sum -= tr[tr[lpos[i]].ls].val;
  }
  for (int i = 1; i <= R; ++i) {
    sum += tr[tr[rpos[i]].ls].val;
  }
  if (sum >= k) {
    for (int i = 1; i <= L; ++i) {
      lpos[i] = tr[lpos[i]].ls;
    }
    for (int i = 1; i <= R; ++i) {
      rpos[i] = tr[rpos[i]].ls;
    }
    return query(l, mid, k);
  }
  for (int i = 1; i <= L; ++i) {
    lpos[i] = tr[lpos[i]].rs;
  }
  for (int i = 1; i <= R; ++i) {
    rpos[i] = tr[rpos[i]].rs;
  }
  return query(mid + 1, r, k - sum);
}

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("testdata.in", "r", stdin);
  freopen("testdata.out", "w", stdout);
#else
  freopen("P2617 Dynamic Rankings.in", "r", stdin);
  freopen("P2617 Dynamic Rankings.out", "w", stdout);
#endif
#endif

  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    hash[++hash[0]] = a[i];
  }
  for (int i = 1; i <= m; ++i) {
    scanf("\n%c", &q[i].opt);
    if (q[i].opt == 'Q')
      scanf("%d%d%d", &q[i].l, &q[i].r, &q[i].k);
    else
      scanf("%d%d", &q[i].x, &q[i].y), hash[++hash[0]] = q[i].y;
  }
  std::sort(hash + 1, hash + hash[0] + 1);
  hash[0] = std::unique(hash + 1, hash + hash[0] + 1) - hash - 1;
  for (int i = 1, tmp = 1; i <= n; tmp = ++i) {
    a[i] = std::lower_bound(hash + 1, hash + hash[0] + 1, a[i]) - hash;
    while (tmp <= n) {
      modify(rt[tmp], 1, hash[0], a[i], true);
      tmp += lowbit(tmp);
    }
  }
  for (int i = 1; i <= m; ++i) {
    if (q[i].opt == 'Q') {
      L = R = 0;
      int tmp = q[i].l - 1;
      while (tmp) {
        lpos[++L] = rt[tmp];
        tmp -= lowbit(tmp);
      }
      tmp = q[i].r;
      while (tmp) {
        rpos[++R] = rt[tmp];
        tmp -= lowbit(tmp);
      }
      printf("%d\n", hash[query(1, hash[0], q[i].k)]);
    } else {
      int tmp = q[i].x;
      while (tmp <= n) {
        modify(rt[tmp], 1, hash[0], a[q[i].x], false);
        tmp += lowbit(tmp);
      }
      tmp = q[i].x;
      q[i].y = std::lower_bound(hash + 1, hash + hash[0] + 1, q[i].y) - hash;
      while (tmp <= n) {
        modify(rt[tmp], 1, hash[0], q[i].y, true);
        tmp += lowbit(tmp);
      }
      a[q[i].x] = q[i].y;
    }
  }
  return 0;
}